using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Core.Graphics;
using Core.GameObjects;
using Core.Graphics.Animations;

namespace WorldEditor.Tiles
{
    public partial class CharacterTileViewer : UserControl
    {
        public Rotation Rotation
        {
            get { return _Rotation; }
            set { _Rotation = value; }
        }

        protected TileSet _TileSet;
        protected Animation _Animation;
        protected Rotation _Rotation;

        public CharacterTileViewer(TileSet TileSet, Rotation rotation)
        {
            InitializeComponent();

            _Rotation = rotation;
            _TileSet = TileSet;
            SetAnimation();
        }

        public CharacterTileViewer() 
        {
            InitializeComponent();

            SetAnimation();
        }

        public void SetTileSet(TileSet ts)
        {
            _TileSet = ts;
        }

        public bool AnimationEnabled
        {
            get { return timerChar.Enabled; }
            set { timerChar.Enabled = value; }
        }

        public virtual void SetAnimation()
        {
            //_Animation = new Animation(3, 0, 1, 0.2f, AnimationTypes.SeeSaw);
            //_Animation.RunAnimation = true;
        }

        protected int GetFirstAnimationTile()
        {
            int firstTile;
            //Up, right, down, left
            switch (_Rotation)
            {
                case Rotation.Up:
                    firstTile = 0;
                    break;
                case Rotation.Right:
                    firstTile = 3;
                    break;
                case Rotation.Down:
                    firstTile = 6;
                    break;
                case Rotation.Left:
                    firstTile = 9;
                    break;
                default:
                    firstTile = 0;
                    break;
            }

            return firstTile;
        }

        private void timerChar_Tick(object sender, EventArgs e)
        {
            //Get the next frame
            _Animation.GetNextAnimationFrame();
            //Draw
            Draw();
        }

        private void Draw()
        {
            //int SpriteID = GetFirstAnimationTile() + _Animation.TileAnimationFrame;

            //Bitmap bmp = TileSetTileBitmaps.GetTileBitmap(new SpriteID(SpriteID, _TileSet.ID), TileSetTypes.Characters);

            //pbAnimate.Image = Image.FromHbitmap(bmp.GetHbitmap());
        }
    }
}
